<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta http-equiv="expires" content="0">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<title>homechild</title>
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
	</head>
	<body>
		<div id="content">
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron plist" id="plist" style="margin:0px;">
						
					</ul>
				</div>
			</div>
		</div>
		<div id="noRecord" style="text-align: center;margin-top:3rem;display: none;">
			<img src="../../img/login/norecord.png" style="width:0.95rem" />
		</div>
		 
	<script src="../../js/resize.js"></script>
	<script src="../../js/mui.min.js"></script> 
	<script src="../../js/ajaxFun.js"></script>
 <script>
	var data = {
		pageNo: 1,
		pageSize:10,
	};
 	var table = document.getElementById("plist");
 	(function($, doc) {
			$.plusReady(function() {
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							 callback: pulldownRefresh
						},
						up: { 
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				
			})
		}(mui, document))
 	
 			if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);
				});
			} else {
				mui.ready(function() {					
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
			
 	function pulldownRefresh() {
			setTimeout(function() {
					mui('#pullrefresh').pullRefresh().scrollTo(0,0,100);
					var url = baseUrl + 'stock/get/index/page.do';
					data.pageNo=1;table.innerHTML='';
					mui('#pullrefresh').pullRefresh().refresh(true);
					ajaxFun.postFun(url,data,'',formList);		 
			}, 100);	
	}
			
		function pullupRefresh() { 
//			setTimeout(function() {
				var url = baseUrl + 'stock/get/index/page.do';
				ajaxFun.postFun(url,data,'',formList);
//			}, 0);	
		}
		
  
		var total = 0;
		function formList(datalist) {
//			setTimeout(function() {
				data.pageNo++;
				var list = datalist.data.dataList ? datalist.data.dataList : [];
				total = datalist.data.total >= 0 ? datalist.data.total : total;
				if(list.length > 0) { 
					for(var i = 0, len = list.length; i < len; i++) {
						var temp = list[i];
						var li = document.createElement('li');
						li.className = 'pitem mui-table';
						var html = '';
						temp.factoryName = temp.factoryName ? temp.factoryName : '';
						temp.stock = temp.stock ? countUnit(temp.stock) : 0;
						temp.productName = temp.productName ? temp.productName : '';
						temp.imgUrl = temp.imgUrl ? routeUrl + temp.imgUrl : 'default.img';
						html += '<div class="mui-table-cell" style="width:1.05rem;vertical-align: middle;">' +
							'<img src="' + temp.imgUrl + '" style="width:1.05rem;vertical-align: middle;" />' +
							'</div>' +
							'<div class="mui-table-cell" style="vertical-align: middle;padding-left:0.32rem">' +
							'<p>' + temp.productName + '</p>' +
							'<p>库存：<span>' + temp.stock + '</span> 箱</p>' +
							'<p style="margin-bottom:0px">公司：' + temp.factoryName + '</p>' +
							'</div>';
						li.innerHTML = html;
						li.setAttribute('data-productNo', temp.productNo);
						li.addEventListener('tap', function() {
							var _self = this;
							openWindow('productInfo.html', 'productInfo', {
								productNo: _self.getAttribute('data-productNo'),
							});
						})
						table.appendChild(li);
					}
					document.getElementById("noRecord").style.display = 'none';
					document.getElementById("content").style.display = 'block';
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					var liLen = document.querySelectorAll('.pitem').length;
					if(liLen >= total) {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
					}
				} else {
					if(total==0){
						document.getElementById("noRecord").style.display = 'block';
						document.getElementById("content").style.display = 'none';
					}
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				}
//			},200);
		}
 </script>
					
	</body>
</html>
